<template>
  <el-dialog
      title="修改信息"
      :visible.sync="editDialogVisible"
      @close="DialogClose('editDialogRef')">

    <el-form label-width="100px" ref="editDialogRef" :rules="editRules" :model="editUser">

      <el-form-item :label="item.label" v-for="(item, index) of formLIst" :key="index" :prop="item.prop">
        <el-input v-model="editUser[item.name]" :disabled="item.dis"></el-input>
      </el-form-item>


      <el-form-item label="邮箱" prop="email">
        <el-input v-model="editUser.email"></el-input>
      </el-form-item>

      <el-form-item label="手机号码" prop="mobile">
        <el-input v-model="editUser.mobile"></el-input>
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="editDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editUserClick">确 定</el-button>
  </span>
  </el-dialog>
</template>

<script>
export default {
  name: "edit",
  props:{
    editDialogVisible:{
      type:Boolean,
      default:false
    },
    editRules:{
      type:Object,
      default: {}
    },
    editUser:{
      type:Object,
      default: {}
    },
    editUrl:{
      type:String,
      default:''
    },
    editData:{
      type:Object,
      default:{}
    },
    formLIst:{
      type:Array,
      default(){
        return []
      }
    }
  },
  methods:{
    DialogClose(ref){
      this.$refs[ref].resetFields()
    },
    editUserClick(){

      this.$refs.editDialogRef.validate(async valid => {
        if (!valid) return
        const {data:res} = await this.$http.put(this.editUrl,this.editData)
        // console.log(res)
        if (res.meta.status !== 200) return this.$Message.error("修改失败")
        this.$Message.success("修改用户成功")

        this.editDialogVisible = false

        this.$emit("getList")

      })
    }
  }
}
</script>

<style scoped>

</style>